package com.android.equipment.dao.operate;

import com.android.equipment.ObjectBox;
import com.android.equipment.dao.TeamGroupDetail;
import com.android.equipment.dao.TeamGroupDetail_;

import java.util.List;

import io.objectbox.Box;
import io.objectbox.query.Query;

public class DaoTeamGroupDetail {
    static Box<TeamGroupDetail> teamGroupDetailBox;
    private static DaoTeamGroupDetail instance;

    private DaoTeamGroupDetail() {
    }

    public static DaoTeamGroupDetail getInstance() {
        if (instance == null) {
            instance = new DaoTeamGroupDetail();
            teamGroupDetailBox = ObjectBox.get().boxFor(TeamGroupDetail.class);
        }
        return instance;
    }


    public void addTeamGroupDetail(TeamGroupDetail teamGroupDetail) {
        teamGroupDetailBox.put(teamGroupDetail);
    }

    public List<TeamGroupDetail> getTeamGroupDetailByGroupId(long groupId){
        Query<TeamGroupDetail> query = teamGroupDetailBox.query().equal(TeamGroupDetail_.groupId, groupId).build();
        List<TeamGroupDetail> teamGroupDetailList = query.find();
        query.close();
        return teamGroupDetailList;
    }

    public List<TeamGroupDetail> getTeamGroupDetailByGroupIdAndPeopleId(long groupId, long peopleId){
        Query<TeamGroupDetail> query = teamGroupDetailBox.query().equal(TeamGroupDetail_.groupId, groupId).equal(TeamGroupDetail_.peopleId, peopleId).build();
        List<TeamGroupDetail> teamGroupDetailList = query.find();
        query.close();
        return teamGroupDetailList;
    }

    public void deleteTeamGroupDetailByGroupIdAndPeopleId(long groupId, long peopleId) {
        Query<TeamGroupDetail> query = teamGroupDetailBox.query().equal(TeamGroupDetail_.groupId, groupId).equal(TeamGroupDetail_.peopleId, peopleId).build();
        List<TeamGroupDetail> teamGroupDetailList = query.find();
        query.close();
        teamGroupDetailBox.remove(teamGroupDetailList);
    }

    public void deleteTeamGroupDetailByGroupId(long groupId) {
        Query<TeamGroupDetail> query = teamGroupDetailBox.query().equal(TeamGroupDetail_.groupId, groupId).build();
        List<TeamGroupDetail> teamGroupDetailList = query.find();
        query.close();
        teamGroupDetailBox.remove(teamGroupDetailList);
    }

    public void deleteTeamGroupDetailByPeopleId(long peopleId) {
        Query<TeamGroupDetail> query = teamGroupDetailBox.query().equal(TeamGroupDetail_.peopleId, peopleId).build();
        List<TeamGroupDetail> teamGroupDetailList = query.find();
        query.close();
        teamGroupDetailBox.remove(teamGroupDetailList);
    }
}
